#!/usr/bin/perl  
# Writen by kalyan varma (kalyan@rtns.org)
# http://kalyanvarma.net/
#
# Copyright (c) Kalyan Varma 
# All rights reserved.



use Frontier::Client;
    
$server_url = 'http://www.livejournal.com/interface/xmlrpc/';


$username = '';
$password = '';
$post_url = 'http://myserver.com/cgi-bin/lj.pl?ItemID=';


$server = Frontier::Client->new(url => $server_url);
    
$result = $server->call('LJ.XMLRPC.getevents',{ 'username' => $username, 
                                                'password' => $password , 
                                                'ver' => 1, 
                                                'selecttype' => 'one',
                                                'itemid' => -1,
                                                'noprops' => 1,
                                                'lineendings' => 'unix'});

$post = $result->{'events'};
$date = @$post[0]->{'eventtime'};
$itemid = @$post[0]->{'itemid'};
$subject = @$post[0]->{'subject'};
$content = @$post[0]->{'event'};
$lineendings = 'unix'; 

###############################################

my ($year,$mon,$day,$hour,$min);
$lineendings = 'unix'; 
$itemid_web =  ( @$post[0]->{'itemid'} * 256 ) + @$post[0]->{'anum'} ;

$content = $content . "\n" . "<img src=\"" . $post_url . $itemid_web . "\" height=0 width=0 border=0>" ;

if ( $date =~ /(.*)-(.*)-(.*) (.*):(.*):(.*)/) {
    $year = $1; 
    $mon = $2;
    $day = $3;
    $hour = $4;
    $min = $5;
}

$result = $server->call('LJ.XMLRPC.editevent', { 'username' => $username,
                                                'password' => $password ,
                                                'ver' => 1 ,
                                                'itemid' => $itemid,
                                                'event' => $content,
                                                'lineendings' => $lineendings,
                                                'subject' => $subject ,
                                                'year' => $year,
                                                'mon' => $mon,
                                                'day' => $day,
                                                'hour' => $hour,
                                                'min' => $min });

$output = $result->{'itemid'};
#print $output . "\n";
                                                
